#ifndef GAMEWIDGET_H
#define GAMEWIDGET_H

#include <QWidget>
#include <QTimer>
#include <QPushButton>
#include <QLabel>
#include <QPixmap>
#include <QPushButton>

// 定义子弹结构体
struct Bullet {
    int x;
    int y;
    bool active;
};

// 定义敌机结构体
struct Enemy {
    int x;
    int y;
    int speed;
    bool active;
};

class GameWidget : public QWidget {
    Q_OBJECT

private:
    QPixmap backgroundImage;    // 背景图片
    QWidget *startWidget;       // 开始界面
    QPushButton *startButton;   // 开始按钮
    QWidget *gameOverWidget;    // 游戏结束界面的Widget
    QLabel *gameOverLabel;      // 游戏结束提示标签
    QLabel *scoreLabel;         // 分数显示标签
    QPushButton *restartButton; // 重新开始按钮
    QTimer *gameTimer;
    int playerX;
    QVector<Bullet> bullets;
    QVector<Enemy> enemies;
    int score;
    bool gameOver;
     void showStartScreen();

public:
    explicit GameWidget(QWidget *parent = nullptr);
    void startGame();

protected:
    void paintEvent(QPaintEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;

private slots:
    void updateGame();
    void restartGame();
    void exitGame();

private:
    void resetGame();
    void drawPlayer(QPainter &painter, int x, int y);
    void drawEnemy(QPainter &painter, int x, int y);
    void endGame();
};

#endif // GAMEWIDGET_H
